package com.lyb.spzx.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyb.spzx.manager.mapper.BrandMapper;
import com.lyb.spzx.manager.service.BrandService;
import com.lyb.spzx.model.entity.product.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BrandServiceImpl implements BrandService {

    @Autowired
    BrandMapper brandMapper;

    @Override
    public PageInfo<Brand> findByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Brand> brandList =  brandMapper.findBrandByPage();
        PageInfo<Brand> brandPageInfo = new PageInfo<>(brandList);
        return brandPageInfo;
    }

    @Override
    public void addBrand(Brand brand) {
        brandMapper.addBrand(brand);
    }

    @Override
    public void updateBrand(Brand brand) {
        brandMapper.updateBrandById(brand);
    }

    @Override
    public void deleteById(Integer id) {
        brandMapper.deleteById(id);
    }

    /**
     * 查询所有品牌
     * @return
     */
    @Override
    public List<Brand> findAllBrand() {
        List<Brand> brandList = brandMapper.findAll();
        return brandList;
    }
}
